package com.gccloud.design.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gccloud.design.dao.SdActionConfDao;
import com.gccloud.design.entity.SdActionConfEntity;
import com.gccloud.design.service.SdActionConfQueryService;
import com.gccloud.starter.core.vo.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 实现功能【操作按钮配置业务实现层】
 *
 * @author hu.hongdou
 * @date 2022/2/21
 */
@Service
public class SdActionConfQueryServiceImpl extends ServiceImpl<SdActionConfDao, SdActionConfEntity> implements SdActionConfQueryService {

    private static final Logger log = LoggerFactory.getLogger(SdActionConfQueryServiceImpl.class);

    @Resource
    private SdActionConfDao sdActionConfDao;

    /**
     * 查询操作按钮
     */
    @Override
    public Map<String, Object> querySdActionConf(String actionName, PageVO pageObj) {
        Map<String, Object> map = new HashMap<>(3);
        Page<SdActionConfEntity> page = new Page<>(pageObj.getCurrent(), pageObj.getSize());
        map.put("list", sdActionConfDao.querySdActionConf(actionName, page));
        map.put("total", page.getTotal());
        return map;
    }

    @Override
    public boolean saveSdActionConf(SdActionConfEntity entity) {
        try {
            int result = sdActionConfDao.saveSdActionConf(entity);
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("---------------------------新增按钮失败，" + e.getMessage());
            return false;
        }
    }

    @Override
    public boolean modefySdActionConf(SdActionConfEntity entity) {
        try {
            int result = sdActionConfDao.modefySdActionConf(entity);
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("---------------------------更新按钮失败，" + e.getMessage());
            return false;
        }
    }

    @Override
    public boolean deleteSdActionConf(int actionId) {
        boolean result = true;
        try {
            sdActionConfDao.deletdSdActionConfByActionId(actionId);
        } catch (Exception e) {
            result = false;
            e.printStackTrace();
            log.error("---------------------------删除按钮失败，" + e.getMessage());
        }
        return result;
    }
}
